<template>
	<view class="padding flex flex-direction"><button class="cu-btn bg-mauve margin-tb-sm lg" @click="toPay">立即支付</button></view>
</template>

<script>
import { order } from '@/config/mixins.js';
export default {
	mixins: [order],
	props: {
		orderId: {
			type: String,
			default() {
				return '';
			}
		}
	},
	data() {
		return {};
	},
	methods: {
		toPay() {
			let _this = this;
			this.$api
				.order_pay({
					paytype:'',
					method:'',
					order_id: this.orderId
				})
				.then(res => {
					if (res.code) {
						uni.requestPayment({
							provider: this.paytype == 'alipay' ? 'alipay' : 'wxpay',
							orderInfo: res.data.orderInfo, //微信、支付宝订单数据
							success: function(rest) {
								if (e.errMsg === 'requestPayment:ok') {
									_this.$common.successToShow(res.msg, () => {
										_this.getOrderDetail();
									});
								}
							},
							fail: function(err) {
								_this.$common.errorToShow('fail:' + JSON.stringify(err));
							}
						});
					} else {
						this.$common.errorToShow(res.msg);
					}
				});
		}
	}
};
</script>

<style></style>
